package com.example.com.skills_utf8;

import java.util.HashMap;
import java.util.Map;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONObject;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.utils.SocketHttpRequester;

public class _34PostStringActivity extends Activity{

	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_34_post_string);
		
		
		Button btn_post = (Button)findViewById(R.id.btn_post);
		btn_post.setOnClickListener( new OnClickListener() {
			
			@Override
			public void onClick(View v) {

				
				
				String v1 = "{ \"currentPage\": 1  , \"pageSize\": 10,  ";  //
				
				String value = 
				" \"params\": {\"account\": 69,\"catalog\": null,\"customAttribute\": null}  }"
				;
				
				value = v1 + value;
				
				System.out.println(value);
				
				final  Map<String, String> params = new HashMap<String, String>();
				 params.put("params", value);
					
				
					new Thread(){
						public void run() {
							try {
								
							String path ="http://114.80.156.57:36080/mobile/services/account/getItemListOfAccountFavoriteByAccountAndParamPageData";
						//	String result =SocketHttpRequester.post(path, params);
						//	System.out.println(result);
							
							
							
							
							
							

							HttpPost  request  = new HttpPost( path );
							// 先封装一个 JSON 对象

							///*
							
							JSONObject param0 = new JSONObject();
							param0.put("account", 69);
							param0.put("catalog", null);
							param0.put("customAttribute", null);
							
							JSONObject param = new JSONObject();
							param.put("currentPage", 1);
							param.put("pageSize", 10);
							param.put("params", param0);
							
							//*/
							
							// 绑定到请求 Entry
							System.out.println(param.toString());
							StringEntity se = new StringEntity(param.toString());
						//	String param = params.get("params");
						//	StringEntity se = new StringEntity( param );
							request.setEntity(se);

							// 发送请求
							request.addHeader("Content-Type", "application/json");
							HttpResponse httpResponse = new DefaultHttpClient().execute(request);
							// 得到应答的字符串，这也是一个 JSON 格式保存的数据
							String retSrc = EntityUtils.toString(httpResponse.getEntity());
							System.out.println(""+retSrc);
							
							
							
							
							} catch (Exception e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
							
							

							
							
							
						};
						
					}.start();
					
					
					
				
				
				
			}
		});
		
		
		
		
	}
	
	
	
	
	
}
